package day012.duotai.demo03;

public class Test {
    public static void main(String[] args) {
        Animal c = new Cat();
        useAnimal(c);

        System.out.println("---------------------------");

        Animal d = new Dog();
        useAnimal(d);

        System.out.println("----------------------------");

        Animal p = new Pig();
        useAnimal(p);
    }

    public static void useAnimal(Animal a) {
        a.eat();

        if (a instanceof Cat) {
            Cat cat = (Cat) a;
            cat.catchMouse();
        }
        if (a instanceof Dog) {
            Dog dog = (Dog) a;
            dog.lookDoor();
        }

        if (a instanceof Pig) {
            ((Pig) a).sleep();
        }
    }
}
